#ifndef WAVETOOL_H
#define WAVETOOL_H
#include <QWidget>
#include <GL/glu.h>
#include <QtOpenGL>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_4_5_Core>
#include <QPainter>
#include <QLinearGradient>
#include <QDebug>
#include <QQueue>
#include <algorithm>
#include <QList>
#include <cfloat>

class Point2d{
public:
    Point2d():x(0), y(0){ }
    Point2d(float x, float y) : x(x), y(y){ }
public:
    float x;
    float y;
};

class Point3d{
public:
    Point3d():x(0), y(0), z(0){ }
    Point3d(float x, float y, float z) : x(x), y(y), z(z){ }
public:
    float x;
    float y;
    float z;
};

class PaintStyle
{
public:
    PaintStyle();
    PaintStyle(QColor color, float lineWidth);
public:
    float colorR;
    float colorG;
    float colorB;
    float lineWidth;
};

class Text2DStyle
{
public:
    Text2DStyle();
    Text2DStyle(QColor color ,QFont font);
public:
    QColor mColor;
    QFont mFont;
};

class CTexturePoint
{
public:
    CTexturePoint();
    CTexturePoint(float x, float y, float z);
    virtual ~CTexturePoint();
    void createTexture(bool bDelTexture = true);
    void bindImg(QImage* img);

public:
    QOpenGLTexture* texture;
    QImage* mImg;

    /*texture所在的三维坐标*/
    float x;
    float y;
    float z;
};

class CAxisText
{
public:
    CAxisText(int nums);
    virtual ~CAxisText();
    CAxisText* setText(int index, QString text);
    CAxisText* setPos(int index, float x, float y, float z);
    void createTextures();
    void clearTextures();
    void clear();
    int getNumAndPaint();
public:
    CTexturePoint** mTexture;
    int mNum;
    QFont mFont;
    QColor mColor;
    bool mBUpdateTexture;
private:
    bool mBPaint;
};


class CText2DTool
{
public:
    CText2DTool();
    virtual ~CText2DTool();
    void initGL();
    /**
     * @brief drawTextLT 根据文字左上为目标进行绘制
     * @param tp  纹理
     * @param wx  绘制的左上角的x坐标
     * @param wy  绘制的左上角的y坐标
     */
    void drawTextLT(CTexturePoint* tp, GLdouble wx, GLdouble wy);
    /**
     * @brief drawTextLT 以文字右上点进行绘制
     * @param tp  纹理
     * @param wx  绘制的右上角的x坐标
     * @param wy  绘制的右上角的y坐标
     */
    void drawTextRT(CTexturePoint* tp, GLdouble wx, GLdouble wy);
public:
    QOpenGLVertexArrayObject VAO;
    QOpenGLBuffer VBO;
    QOpenGLShaderProgram shaderProgram;
};

class CLegend
{
public:
    CLegend();
    virtual ~CLegend();
    virtual void paintColorCard(QPaintDevice *);
    virtual void setColor(QColor color);
    virtual void randomColor(int num);
    virtual void mapping(float val, float* r, float* g, float* b);
    virtual void mappingRange(float min, float max);
    virtual QColor mapping(int val, int min, int max);
protected:
    QRect rect;
    float scale;
    QList<QColor> colors;
};



#endif // WAVETOOL_H
